from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-11 14:02:25.528870
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 11, Jun, 2022
Time: 14:02:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5272
Nobs: 684.000 HQIC: -49.8924
Log likelihood: 8497.06 FPE: 1.70563e-22
AIC: -50.1230 Det(Omega_mle): 1.49677e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.309115 0.058923 5.246 0.000
L1.Burgenland 0.105524 0.038283 2.756 0.006
L1.Kärnten -0.109160 0.020188 -5.407 0.000
L1.Niederösterreich 0.201917 0.079867 2.528 0.011
L1.Oberösterreich 0.116380 0.078599 1.481 0.139
L1.Salzburg 0.255627 0.040833 6.260 0.000
L1.Steiermark 0.044926 0.053429 0.841 0.400
L1.Tirol 0.107916 0.043193 2.498 0.012
L1.Vorarlberg -0.057436 0.037701 -1.523 0.128
L1.Wien 0.029855 0.069583 0.429 0.668
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.043101 0.124599 0.346 0.729
L1.Burgenland -0.034014 0.080954 -0.420 0.674
L1.Kärnten 0.039964 0.042690 0.936 0.349
L1.Niederösterreich -0.181089 0.168886 -1.072 0.284
L1.Oberösterreich 0.440146 0.166206 2.648 0.008
L1.Salzburg 0.285211 0.086345 3.303 0.001
L1.Steiermark 0.106723 0.112981 0.945 0.345
L1.Tirol 0.316144 0.091335 3.461 0.001
L1.Vorarlberg 0.027057 0.079722 0.339 0.734
L1.Wien -0.035706 0.147140 -0.243 0.808
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188748 0.030268 6.236 0.000
L1.Burgenland 0.088591 0.019666 4.505 0.000
L1.Kärnten -0.007603 0.010371 -0.733 0.463
L1.Niederösterreich 0.259059 0.041027 6.314 0.000
L1.Oberösterreich 0.143107 0.040376 3.544 0.000
L1.Salzburg 0.045177 0.020975 2.154 0.031
L1.Steiermark 0.023449 0.027446 0.854 0.393
L1.Tirol 0.089200 0.022188 4.020 0.000
L1.Vorarlberg 0.057260 0.019367 2.957 0.003
L1.Wien 0.114137 0.035744 3.193 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112262 0.030529 3.677 0.000
L1.Burgenland 0.044967 0.019835 2.267 0.023
L1.Kärnten -0.014000 0.010460 -1.338 0.181
L1.Niederösterreich 0.186797 0.041381 4.514 0.000
L1.Oberösterreich 0.312861 0.040724 7.682 0.000
L1.Salzburg 0.103462 0.021156 4.890 0.000
L1.Steiermark 0.107859 0.027683 3.896 0.000
L1.Tirol 0.102443 0.022379 4.578 0.000
L1.Vorarlberg 0.068085 0.019534 3.486 0.000
L1.Wien -0.025652 0.036052 -0.712 0.477
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122639 0.056187 2.183 0.029
L1.Burgenland -0.047461 0.036506 -1.300 0.194
L1.Kärnten -0.045962 0.019251 -2.388 0.017
L1.Niederösterreich 0.147578 0.076158 1.938 0.053
L1.Oberösterreich 0.149877 0.074950 2.000 0.046
L1.Salzburg 0.282397 0.038937 7.253 0.000
L1.Steiermark 0.052854 0.050948 1.037 0.300
L1.Tirol 0.167910 0.041187 4.077 0.000
L1.Vorarlberg 0.097753 0.035950 2.719 0.007
L1.Wien 0.074888 0.066352 1.129 0.259
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061412 0.044418 1.383 0.167
L1.Burgenland 0.032016 0.028859 1.109 0.267
L1.Kärnten 0.051380 0.015219 3.376 0.001
L1.Niederösterreich 0.208158 0.060206 3.457 0.001
L1.Oberösterreich 0.303209 0.059250 5.117 0.000
L1.Salzburg 0.043400 0.030781 1.410 0.159
L1.Steiermark 0.007456 0.040276 0.185 0.853
L1.Tirol 0.136809 0.032560 4.202 0.000
L1.Vorarlberg 0.074247 0.028420 2.612 0.009
L1.Wien 0.082468 0.052454 1.572 0.116
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171574 0.053299 3.219 0.001
L1.Burgenland 0.000781 0.034629 0.023 0.982
L1.Kärnten -0.064201 0.018261 -3.516 0.000
L1.Niederösterreich -0.090137 0.072244 -1.248 0.212
L1.Oberösterreich 0.201274 0.071097 2.831 0.005
L1.Salzburg 0.054963 0.036935 1.488 0.137
L1.Steiermark 0.240731 0.048329 4.981 0.000
L1.Tirol 0.499516 0.039070 12.785 0.000
L1.Vorarlberg 0.052869 0.034102 1.550 0.121
L1.Wien -0.065004 0.062941 -1.033 0.302
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.154489 0.060034 2.573 0.010
L1.Burgenland -0.007394 0.039005 -0.190 0.850
L1.Kärnten 0.062079 0.020569 3.018 0.003
L1.Niederösterreich 0.193238 0.081373 2.375 0.018
L1.Oberösterreich -0.070614 0.080082 -0.882 0.378
L1.Salzburg 0.208357 0.041603 5.008 0.000
L1.Steiermark 0.135359 0.054437 2.487 0.013
L1.Tirol 0.069023 0.044007 1.568 0.117
L1.Vorarlberg 0.133611 0.038412 3.478 0.001
L1.Wien 0.124278 0.070895 1.753 0.080
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.373440 0.035032 10.660 0.000
L1.Burgenland 0.000843 0.022761 0.037 0.970
L1.Kärnten -0.022514 0.012003 -1.876 0.061
L1.Niederösterreich 0.217444 0.047483 4.579 0.000
L1.Oberösterreich 0.212500 0.046730 4.547 0.000
L1.Salzburg 0.042442 0.024276 1.748 0.080
L1.Steiermark -0.018154 0.031765 -0.571 0.568
L1.Tirol 0.101864 0.025680 3.967 0.000
L1.Vorarlberg 0.064937 0.022414 2.897 0.004
L1.Wien 0.029180 0.041369 0.705 0.481
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038042 0.127066 0.183361 0.148732 0.107765 0.090250 0.047454 0.213084
Kärnten 0.038042 1.000000 -0.017653 0.133734 0.053395 0.092300 0.439232 -0.057294 0.093720
Niederösterreich 0.127066 -0.017653 1.000000 0.331813 0.137120 0.289524 0.082371 0.170460 0.308915
Oberösterreich 0.183361 0.133734 0.331813 1.000000 0.224614 0.316794 0.167002 0.153930 0.262813
Salzburg 0.148732 0.053395 0.137120 0.224614 1.000000 0.134428 0.105546 0.125936 0.133340
Steiermark 0.107765 0.092300 0.289524 0.316794 0.134428 1.000000 0.140720 0.119378 0.063934
Tirol 0.090250 0.439232 0.082371 0.167002 0.105546 0.140720 1.000000 0.093113 0.144007
Vorarlberg 0.047454 -0.057294 0.170460 0.153930 0.125936 0.119378 0.093113 1.000000 0.006930
Wien 0.213084 0.093720 0.308915 0.262813 0.133340 0.063934 0.144007 0.006930 1.000000